package org.jeecg.convert;

import org.flowable.bpmn.model.UserTask;
import org.jeecg.Utils.CollectionUtils;
import org.jeecg.flowable.entity.definition.BpmTaskAssignRule;

import java.util.List;
import java.util.Map;

public class BpmTaskAssignRuleConvert {

    public static List<BpmTaskAssignRule> convertList(List<UserTask> tasks, List<BpmTaskAssignRule> rules) {
        Map<String, BpmTaskAssignRule> ruleMap = CollectionUtils.convertMap(rules, BpmTaskAssignRule::getTaskDefinitionKey);
        // 以 UserTask 为主维度，原因是：流程图编辑后，一些规则实际就没用了。
        return CollectionUtils.convertList(tasks, task -> {
            BpmTaskAssignRule respVO = ruleMap.get(task.getId());
            if (respVO == null) {
                respVO = new BpmTaskAssignRule();
                respVO.setTaskDefinitionKey(task.getId());
            }
            respVO.setTaskDefinitionName(task.getName());
            return respVO;
        });
    }
}
